package com.yanqu.road.dao.impl.config;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.config.system.UserName;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class NameDaoImpl extends TempDao {

    public List<UserName> getUserNameList() {
        ResultSet rs = null;
        CallableStatement call = null;
        String sql = "select * from t_p_user_name";
        List<UserName> dataList = new ArrayList<>();
        try {
            getDb().setConnName(DbNameStrategy.getConfigDb());
            call = getDb().getConnection().prepareCall(sql);
            rs = call.executeQuery();
            while (rs.next()) {
                UserName data = new UserName();
                data.setName(rs.getString("name"));
                data.setNameW(rs.getString("nameW"));
                data.setSurname(rs.getString("surname"));
                data.setLanguage(rs.getString("language"));
                dataList.add(data);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }

        return dataList;
    }
}
